package Notepad;

import java.util.Scanner;

public class SecuredNotepad extends SimpleNotepad implements iSecuredNotepad {
	private final String password;

	SecuredNotepad(final String password, int countPages) {
		super(countPages);
		this.password = password;
	}


	@Override
	public void addTextInPage(int pageNumber, String text) {

		if (checkPassword())
			super.addTextInPage(pageNumber, text);

	}

	@Override
	public void replaceTextInPage(int pageNumber, String text) {
		if (checkPassword())
			super.replaceTextInPage(pageNumber, text);

	}

	@Override
	public void deleteTextToPage(Page selectedPage) {
		if (checkPassword())
			super.deleteTextToPage(selectedPage);

	}

	@Override
	public void printAllPages() {
		if (checkPassword())
			super.printAllPages();

	}


	@Override
	public boolean checkPassword() {
		// TODO Auto-generated method stub
		String password;
		Scanner s = new Scanner(System.in);

		System.out.println("Enter password:");
		password = s.nextLine();
		if (this.password.equals(password)) {

			return true;

		} else {
			System.out.println("Wrong password!");
			return false;
		}
	}

}
